package cn.harmonyoslearn.navrouter.datas;

import kotlinx.html.S;

import java.util.ArrayList;
import java.util.Objects;

public class NavName {
    public String name;
    public String note;
    public String routerMapPath;
    public String filePath;

    public NavName(String name, String note, String routerMapPath, String filePath) {
        this.name = name;
        this.note = note;
        this.routerMapPath = routerMapPath.replace("//", "/");
        this.filePath = filePath.replace("//", "/");
    }

    public NavName copy() {
        return new NavName(name, note, routerMapPath, filePath);
    }

    public static String toJsonString(NavName navName) {
        return "{" +
                "\"name\":\"" + navName.name +
                "\",\"note\":\"" + navName.note +
                "\",\"routerMapPath\":\"" + navName.routerMapPath +
                "\",\"filePath\":\"" + navName.filePath +
                "\"}";
    }

    public static String toJsonString(ArrayList<NavName> navNames) {
        StringBuilder str = new StringBuilder("[");

        for (NavName navName : navNames) {
            str.append(toJsonString(navName)).append(",");
        }

        str.delete(str.length()-1, str.length());
        return str + "]";
    }


    public static String toNavPageNameTs(NavName navName) {
        String str = "";
        if (!Objects.equals(navName.note, "")) {
            str += "  /**\n   * " + navName.note + "\n   */\n";
        }
        str += "  static " + navName.name + " = \"" + navName.name + "\";\n";
        return str;
    }

    public static String toNavPageNameTs(ArrayList<NavName> navNames) {
        StringBuilder str = new StringBuilder("export class NavPageNames {\n");
        for (NavName navName : navNames) {
            str.append(toNavPageNameTs(navName));
        }
        return str + "}";
    }
}
